#include "stdint.h"
#include "core_riscv.h"
#include "reg.h"
uint32_t counter = 0;
void SysTick_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast")));

void systick_init(uint64_t ticks)
{
    SysTick->SR &= ~(1 << 0); // clear State flag
    SysTick->CMP = ticks;
    SysTick->CNT = 0;
    SysTick->CTLR = 0xF;

    NVIC_SetPriority(SysTicK_IRQn, 15);
    NVIC_EnableIRQ(SysTicK_IRQn);
}

/*********************************************************************
 * @fn      SysTick_Handler
 *
 * @brief   SysTick_Handler.
 *
 * @return  none
 */
void SysTick_Handler(void)

{
    if (SysTick->SR == 1)
    {
        SysTick->SR = 0; // clear State flag
        counter++;
    }
}